class Solution {
public:
    double champagneTower(int poured, int query_row, int query_glass) {
        int m = query_row;
        int n = query_glass;
        vector<double> dp(m+1);
        dp[0] = poured;
        
        for(int i = 1;i <= m;i++){
            for(int j = i;j > 0;j--){
                dp[j] = dp[j] > 1 ? (dp[j]-1) / 2 : 0;
                dp[j] += dp[j-1] > 1 ? (dp[j-1]-1) / 2 : 0;
            }
            dp[0] = dp[0] > 1 ? (dp[0]-1) / 2 : 0;
        }
      
        if(dp[n] >= 1) return 1;
        return dp[n];
    }
};
